package com.msb.serviceverificationcode.controller;

import com.msb.internalcommon.dto.ResponseResult;
import com.msb.internalcommon.reponese.NumberCodeResponse;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: jiudianliu
 * @Date: 2023/3/17 - 03 - 17 - 18:26
 * @Description: com.msb.serviceverificationcode.controller
 * @version: 1.0
 */
@RestController
public class NumberCodeController {
    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size){
        //System.out.println("size:" + size);

        // 获取随机数 0.0-0.1  小数点后14位
        double mathRandom = Math.random();
        //让首位不再是0
        double math = mathRandom*9 + 1;
        //获取小数点前六位随机验证码，将小数点后移五位
        double ma = math * Math.pow( 10 , size - 1 );
        int resultInt = (int)ma;
        System.out.println(resultInt);
        //定义返回值
        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode(resultInt);
        return ResponseResult.success(response);
    }

//    //获取随机数
//    public static void main(String[] args) {
//        // 获取随机数 0.0-0.1  小数点后14位
//        double mathRandom = Math.random();
//        //让首位不再是0
//        double math = mathRandom*9 + 1;
//        //获取小数点前六位随机验证码，将小数点后移五位
//        double ma = math * Math.pow(10,5);
//        int resultInt = (int)ma;
//        System.out.println(resultInt);
//    }
}
